//
//  PYRNEvent.m
//  IHome
//
//  Created by 朱吉峥 on 2020/2/8.
//  Copyright © 2020 com.zhujizheng. All rights reserved.
//

#import "PYRNEvent.h"

@interface PYRNEvent ()

@end

@implementation PYRNEvent

RCT_EXPORT_MODULE()

- (NSArray<NSString *> *)supportedEvents
{
    return @[PYRNAlertNameNotification, PYRNUpdateNotification];
}

- (void)startObserving
{
    for (NSString *name in self.supportedEvents) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:name object:nil];
    }
}

- (void)notificationAction:(NSNotification *)notify
{
    id body = [notify object];
    NSString *name = [notify name];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self sendEventWithName:name body:body];
    });
}

- (void)stopObserving
{
    for (NSString *name in self.supportedEvents) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:name object:nil];
    }
}

@end
